home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / tobase64.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  1.9 KB  |  52 lines

  1. <!--- This example shows the use of ToBinary and ToBase64 --->
  2. <html>
  3. <head>
  4. <title>
  5. ToBase64 Example
  6. </title>
  7. </head>
  8.  
  9. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  10. <BODY  bgcolor="#FFFFD5">
  11.  
  12. <h3>ToBase64 Example</h3>
  13.  
  14. <!----------------------------------------------------------------------
  15. Initialize data.
  16. ----------------------------------------------------------------------->
  17. <CFSet charData ="">
  18. <!----------------------------------------------------------------------
  19. Create a string of all ASCII characters (32-255) and concatenate them together.
  20. ----------------------------------------------------------------------->
  21. <CFLoop index="data" from="32" to="255">
  22.     <CFSet ch=chr(data)>
  23.     <CFSet charData=charData & ch>
  24. </CFLoop>
  25. <p>
  26. The following string is the concatenation of all characters (32 to 255) from the ASCII table.<br>
  27. <cfoutput>#charData#</cfoutput>
  28. </p>
  29. <!----------------------------------------------------------------------
  30. Create a Base 64 representation of this string.
  31. ----------------------------------------------------------------------->
  32. <cfset data64=toBase64(charData)>
  33.  
  34. <!----------------------------------------------------------------------
  35. Convert string to binary.
  36. ----------------------------------------------------------------------->
  37. <CFSet binaryData=toBinary(data64)>
  38. <!----------------------------------------------------------------------
  39. Convert binary back to Base 64.
  40. ----------------------------------------------------------------------->
  41. <CFSet another64=toBase64(binaryData)>
  42. <!----------------------------------------------------------------------
  43. Compare another64 with data64 to ensure that they are equal.
  44. ----------------------------------------------------------------------->
  45. <CFIf another64 eq data64>
  46.     <h3>Base 64 representations are identical.</h3>
  47. <CFElse>
  48.     <h3>Conversion error.</h3>
  49. </CFIf>
  50. </body>
  51. </html>
  52.